<?php
/**
 * 
 *
 * @copyright Copyright (c) 2013
 * @version   1.0
 * 
 * @todo commenter la classe
 **/
class EntityField
{	
	public $id; 
	public $code;
	public $name;
	public $desc;
	public $comment;
	public $type;
	public $sqlColName;
	
	const T_INTEGER = "INTEGER";
	const T_BOOLEAN = "BOOLEAN";
	const T_DECIMAL = "DECIMAL";
	const T_STRING = "STRING";
	
    /**
    * Constructor
    * 
    * @return void
    */    
    public function __construct () {
		$this->id = 0;
    }
												 
	public function cast($value) {
		if ($this->type == EntityField::T_INTEGER)
			return (int) $value;
		if ($this->type == EntityField::T_BOOLEAN)
			return (bool) $value;
		if ($this->type == EntityField::T_DECIMAL)
			return (float) $value;
		if ($this->type == EntityField::T_STRING)
			return (string) $value;

		return $value;
	}
	
	public function getSqlParam() {
		if ($this->type == EntityField::T_INTEGER)
			return 'n:'.$this->code;
		if ($this->type == EntityField::T_BOOLEAN)
			return 'b:'.$this->code;
		if ($this->type == EntityField::T_DECIMAL)
			return 'n:'.$this->code;
		if ($this->type == EntityField::T_STRING)
			return 's:'.$this->code;

		return $value;
	}

	public function getSqlColName() {
		return '`'.$this->sqlColName.'`';
	}

} // END class